<% content_for :content do %>

  <!-- widget grid -->
  <section id="widget-grid" class="">
  
    <div class="row">
      <div class="col-sm-12">
        <div class="well">

          <%= simple_form_for :api_visit_log, url: admin_api_visit_logs_path, :defaults => { :input_html => { :class => "form-control" } }, method: 'get', html: { class: "form-inline" } do |f| %>
            <label>IP地址</label>
            <%= f.input_field :remote_ip, selected: params[:api_visit_log][:remote_ip], collection: ApiVisitLog.select(:remote_ip).uniq.map(&:remote_ip).sort, label: false, prompt: '全部' %>
            <label>客户端编号</label>
            <%= f.input_field :client_id, selected: params[:api_visit_log][:client_id], collection: ApiVisitLog.select(:client_id).uniq.map(&:client_id).reject {|i| !i }.sort, label: false, prompt: '全部' %>
            <label>请求</label>
            <%= f.input_field :request, selected: params[:api_visit_log][:request], collection: ApiVisitLog.select(:request).uniq.map(&:request).sort, label: false, prompt: '全部' %>    
            <label>请求异常</label>
            <%= f.input_field :warned, selected: params[:api_visit_log][:warned], collection: [['异常', true], ['正常', false]], label: false, prompt: '全部' %>
            <br />    
            <br />
            <label>参数</label>
            <%= f.input_field :request_data, value: params[:api_visit_log][:request_data], label: false %>
            <label>HTTP</label>
            <%= f.input_field :response_status, selected: params[:api_visit_log][:response_status], collection: ApiVisitLog.select(:response_status).uniq.map(&:response_status).reject {|i| !i }.sort, label: false, prompt: '全部' %>
            <label>请求时间</label>
            <div class="form-group string">
            <%= f.text_field :start_date, class: "form-control datepicker", "data-dateformat" => "yy-mm-dd", value: params[:api_visit_log][:start_date] %>
            </div>
            <div class="form-group string">
            <%= f.text_field :end_date, class: "form-control datepicker", "data-dateformat" => "yy-mm-dd", value: params[:api_visit_log][:end_date] %>
            </div>
            <%= f.submit "搜索", :class => "btn btn-default"%>
          <% end %>

        </div> <!-- end well div -->

      </div>
    </div>

    <!-- row -->
    <div class="row">

      <div class="col-sm-12">
        <p class="alert alert-success"><i class="fa-fw fa fa-warning"></i> <strong>提示</strong> 耗时以毫秒(ms)为单位。</p>
      </div>

      <!-- NEW WIDGET START -->
      <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        
        <!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget jarviswidget-color-darken" id="wid-id-1" data-widget-editbutton="false" data-widget-colorbutton="false" data-widget-deletebutton="false">
          <!-- widget options:
          usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">

          data-widget-colorbutton="false"
          data-widget-editbutton="false"
          data-widget-togglebutton="false"
          data-widget-deletebutton="false"
          data-widget-fullscreenbutton="false"
          data-widget-custombutton="false"
          data-widget-collapsed="true"
          data-widget-sortable="false"

          -->
          <header>
            <span class="widget-icon"> <i class="fa fa-table"></i> </span>
            <h2>API访问日志</h2>
          </header>

          <!-- widget div-->
          <div>

            <!-- widget edit box -->
            <div class="jarviswidget-editbox">
              <!-- This area used as dropdown edit box -->
            </div>
            <!-- end widget edit box -->

            <!-- widget content -->
            <div class="widget-body no-padding">

              <p class="alert alert-info no-margin">
                <i class="fa-fw fa fa-info"></i>共有<%= @api_visit_logs.total_count %>条记录
              </p>

              <table class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <th>时间</th>
                    <th>耗时</th>
                    <th>IP地址</th>
                    <th>客户端编号</th>
                    <th>版本</th>
                    <th>类型</th>
                    <th>请求</th>
                    <th>请求参数</th>
                    <th>HTTP</th>
                    <th>结果</th>
                    <th>调试信息</th>
                  </tr>
                </thead>
                <tbody>
                <% @api_visit_logs.each do |r| %>
                  <tr id='order-<%= r.id %>'<%= ' class="danger"'.html_safe if r.warned %>>
                    <td>
                      <%= r.created_at.strftime('%H:%M:%S %Y-%m-%d') %>
                    </td>
                    <td>
                      <%= r.duration %>
                    </td>
                    <td>
                      <%= r.remote_ip %>
                    </td>
                    <td>
                      <%= r.client_id %>
                    </td>
                    <td>
                      <%= r.api_version %>
                    </td>
                    <td>
                      <%= r.request_type %>
                    </td>
                    <td>
                      <%= r.request %>
                    </td>
                    <td>
                      <div class="accordion-group">
                        <div class="accordion-heading">
                          <a class="accordion-toggle collapsed" data-toggle="collapse" href="#request-data-<%= r.id %>">请求参数详情</a>
                        </div>
                        <div id="request-data-<%= r.id %>" class="accordion-body collapse" style="height: 0px;">
                          <div class="accordion-inner">
                            <pre><%= r.request_data %></pre>
                          </div>
                        </div>
                      </div>
                    </td>
                    <td>
                      <%= r.response_status %>
                    </td>
                    <td>
                      <div class="accordion-group">
                        <div class="accordion-heading">
                          <a class="accordion-toggle collapsed" data-toggle="collapse" href="#response-<%= r.id %>">结果详情</a>
                        </div>
                        <div id="response-<%= r.id %>" class="accordion-body collapse" style="height: 0px;">
                          <div class="accordion-inner">
                            <pre><%= r.response %></pre>
                          </div>
                        </div>
                      </div>
                    </td>
                    <td>
                      <div class="accordion-group">
                        <div class="accordion-heading">
                          <a class="accordion-toggle collapsed" data-toggle="collapse" href="#debug-<%= r.id %>">调试信息详情</a>
                        </div>
                        <div id="debug-<%= r.id %>" class="accordion-body collapse" style="height: 0px;">
                          <div class="accordion-inner">
                            <pre><%= r.debug %></pre>
                          </div>
                        </div>
                      </div>
                    </td>
                  </tr>
                <% end %>
                </tbody>
              </table>
              <div class="dt-row dt-bottom-row"><div class="row"><div class="col-sm-12 text-right"><%= paginate @api_visit_logs %></div></div></div>
            </div>
            <!-- end widget content -->

          </div>
          <!-- end widget div -->

        </div>
        <!-- end widget -->
  
      </article>
      <!-- WIDGET END -->

    </div>
  
    <!-- end row -->

  </section>
  <!-- end widget grid -->
<% end %>